//+--------------------------------------------------------------------------------
//| Copyright (c) 2012 - 2013 ### an.vuongngocduy
//| This file is a part of Compact Game Engine (CGE)
//+--------------------------------------------------------------------------------
#ifndef __CGE_DIMENSION2_H__
#define __CGE_DIMENSION2_H__

#include "cgeCommons.h"

namespace cge
{
	namespace std
	{
		//! Template class specified the size of 2-dimensional object
		template<class TVal>
		class Dimension2
		{
		public:
			//! Default constructor
			Dimension2()
				: Width(0), Height(0)
			{}


			//! Copy constructor
			template<class TArg>
			Dimension2(const Dimension2<TArg>& dm)
				: Width(dm.Width), Height(dm.Height)
			{}


			//! Construct new size from specified values
			Dimension2(TVal w, TVal h)
				: Width(w), Height(h)
			{}


			//! Set values for size
			void Set(TVal w, TVal h)
			{
				Width = w;	Height = h;
			}


			//! Return the area of current rectangle
			TVal Area() const
			{
				TVal w = Right - Left;
				TVal h = Bottom - Top;
				return (w * h);
			}


			//! Return perimeter of current rectangle
			TVal Perimeter() const
			{
				return 2 * (Width + Height);
			}


			//! Multiply width and height with a scalar
			template<class TArg>
			Dimension2 operator * (TArg scalar) const
			{
				return Dimension2(Width * scalar, Height * scalar);
			}


			//! Divide width and height by a scalar
			template<class TArg>
			Dimension2 operator / (TArg scalar) const
			{
				return Size2(Width / scalar, Height / scalar);
			}

	
			//! Check whether 2 dimension2s are the same
			template<class TArg>
			b8 operator == (const Dimension2<TArg>& dm) const
			{
				return (Width == (TVal)dm.Width) && (Height == (TVal)dm.Height);
			}


			//! Check whether 2 dimension2s are different
			template<class TArg>
			b8 operator != (const Dimension2<TArg>& dm) const
			{
				return (Width != (TVal)dm.Width) || (Height != (TVal)dm.Height);
			}


			//! Multiply current dimension2 with a scalar
			template<class TArg>
			Dimension2& operator *= (TArg scalar)
			{
				Width *= scalar;	Height *= scalar;
				return *this;
			}


			//! Divide current dimension2 by a scalar
			template<class TArg>
			Dimension2& operator /= (TArg scalar)
			{
				Width /= scalar;	Height /= scalar;
				return *this;
			}


		public:
			union
			{
				struct { TVal Width, Height; };
				TVal WnH[2];
			};
		};

		typedef Dimension2<u32> Dimension2u;
	}
}

#endif//__CGE_DIMENSION2_H__